<template>
  <div class="app-container">
    <!-- 表格 -->
    <el-table
      :key="tableKey"
      ref="table"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column label="账号" prop="user.user" align="center" />
      <el-table-column label="姓名" align="center" prop="user.name" />
      <el-table-column label="充值金额" align="center" prop="money" />
      <el-table-column label="支付方式" align="center">
        <template slot-scope="{ row }">{{
          row.type == 1
            ? "支付宝"
            : row.type == 2
              ? "微信"
              : row.type == 3
                ? "后台添加"
                : row.type == 4
                  ? "微信公众号"
                  : ""
        }}</template>
      </el-table-column>
      <el-table-column label="充值后余额" align="center" prop="balance" />
      <el-table-column label="充值时间" align="center" prop="created_at" />
    </el-table>

    <!-- 分页 -->
    <div v-if="total > 0" style="text-align: right">
      <pagination
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.per_page"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { getSupplementList } from '@/api/common'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'FinanceSupplement',
  components: {
    Pagination
  },
  directives: {
    waves
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        per_page: 20
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    clearFilter() {
      this.handleFilter()
    },
    getList() {
      this.listLoading = true
      getSupplementList(this.listQuery)
        .then((response) => {
          const { data, total } = response.data
          this.list = data
          this.total = total
        })
        .finally(() => {
          this.listLoading = false
        })
    }
  }
}
</script>
